package com.itheima.health.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.health.dao.PermissionDao;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.pojo.Permission;
import com.itheima.health.service.PermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
/**
 * @Author gentleman Ma
 * @Date created in 2020/1/3
 * @description 权限管理服务接口实现类
 * @Version 1.0
 */
@Service
@Slf4j
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private PermissionDao permissionDao;
    /**
     * 新增权限
     *
     * @param permission
     */
    @Override
    public void add(Permission permission) {
        permissionDao.insert(permission);

    }

    /**
     * 分页查询
     *
     * @param queryPageBean
     * @return
     */
    @Override
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        Page<Permission> page = permissionDao.selectByConditon(queryPageBean.getQueryString());
        return new PageResult(page.getTotal(),page.getResult());
    }

    /**
     * 根据id删除
     *
     * @param id
     */
    @Override
    public void delete(Integer id) {
        permissionDao.delete(id);
    }

    /**
     * 编辑
     *
     * @param permission
     */
    @Override
    public void edit(Permission permission) {
        permissionDao.update(permission);
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @Override
    public Permission findById(Integer id) {
        return permissionDao.selectById(id);
    }

    @Override
    public List<Permission> findAll() {
        return permissionDao.selectAll();
    }
}
